//
//  MusicHotListCollectionViewCell.m
//  YHYRealx
//
//  Created by yanghuiyan on 16/4/26.
//  Copyright © 2016年 yanghuiyan. All rights reserved.
//

#import "MusicHotListCollectionViewCell.h"

@implementation MusicHotListCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.imagePic = [UIImageView new];
        [self.contentView addSubview:_imagePic];
        
        self.labelUp = [YHYBaseLabel new];
        [self.contentView addSubview:_labelUp];
        
        self.labelDown = [YHYBaseLabel new];
        [self.contentView addSubview:_labelDown];
        
        self.buttonPlay = [UIButton buttonWithType:UIButtonTypeSystem];
        [self.buttonPlay setImage:[[UIImage imageNamed:@"音乐播放"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.imagePic addSubview:_buttonPlay];
        
        self.buttonListen = [UIButton new];
        [self.buttonListen setImage:[[UIImage imageNamed:@"音乐听"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
        [self.imagePic addSubview:_buttonListen];
        
        self.labelNum = [YHYBaseLabel new];
//        self.labelNum.textAlignment = NSTextAlignmentRight;
        [self.imagePic addSubview:_labelNum];
        
        self.labelUp.textColor = [UIColor colorWithRed:0.88 green:0.88 blue:0.89 alpha:1.00];
        self.labelDown.textColor = [UIColor colorWithRed:0.57 green:0.59 blue:0.62 alpha:1.00];
        self.labelNum.textColor = [UIColor colorWithRed:0.88 green:0.88 blue:0.89 alpha:1.00];
        self.labelUp.font = [UIFont systemFontOfSize:15];
        self.labelDown.font = [UIFont systemFontOfSize:14];
        self.labelNum.font = [UIFont systemFontOfSize:13];

    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    [_imagePic mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.contentView).offset(15);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.height.equalTo(@100);
        
    }];
    
    [_labelUp mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_imagePic.mas_bottom).offset(10);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.height.equalTo(@15);
        
    }];
    
    [_labelDown mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_labelUp.mas_bottom).offset(5);
        make.left.equalTo(self.contentView).offset(15);
        make.right.equalTo(self.contentView).offset(-15);
        make.height.equalTo(@15);
        
    }];

    [_buttonPlay mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.equalTo(_imagePic).offset(-5);
        make.bottom.equalTo(_imagePic).offset(-5);
        make.size.mas_offset(CGSizeMake(25, 25));
        
    }];
    
    [_labelNum mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_imagePic).offset(5);
        make.left.equalTo(_buttonListen.mas_right).offset(2);
        make.width.equalTo(@603);
        make.height.equalTo(@20);
        
    }];
    
    [_buttonListen mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(_imagePic).offset(5);
        make.size.mas_equalTo(CGSizeMake(20, 20));
        make.left.equalTo(_imagePic).offset(5);
        
    }];
    
}

- (void)setDetailModel:(MusicDetailDataModel *)detailModel {
    if (_detailModel != detailModel) {
        [_detailModel release];
        _detailModel = detailModel.retain;
    }
    
    _labelUp.text = detailModel.name;
    _labelDown.text = detailModel.desc;
    [_imagePic sd_setImageWithURL:[NSURL URLWithString:detailModel.picUrl]];
    if (detailModel.listenCount.intValue/10000 < 1) {
        ;
        _labelNum.text = detailModel.listenCount.stringValue;
    }else {
        _labelNum.text=[NSString stringWithFormat:@"%d万",detailModel.listenCount.intValue/10000];
    }
    
}

- (void)setRemmondModel:(MusicDetailDataModel *)remmondModel {
    if (_remmondModel != remmondModel) {
        [_remmondModel release];
        _remmondModel = [remmondModel retain];
    }
    
    _labelUp.text = remmondModel.name;
    _labelDown.text = remmondModel.desc;
    [_imagePic sd_setImageWithURL:[NSURL URLWithString:remmondModel.picUrl]];
    if (remmondModel.listenCount.intValue/10000 < 1) {
        ;
        _labelNum.text = remmondModel.listenCount.stringValue;
    }else {
        _labelNum.text=[NSString stringWithFormat:@"%d万",remmondModel.listenCount.intValue/10000];
    }

    
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
